
<%@ page import="com.auctionhaus.Listing" %>
<%@ page import="com.auctionhaus.Customer" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'listing.label', default: 'Listing')}" />
        <title><g:message code="default.show.label" args="[entityName]" /></title>
        <script type="text/javascript" src="jquery-1.4.4.min.js"></script>
    </head>
    <body >
        <div class="body">
            <h1><g:message code="default.show.label" args="[entityName]" /></h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:unless test="${flash.message?.endsWith('Expired')}">
                <div class="dialog">
                    <table>
                        <tbody>
                            <tr class="prop">
                                <th valign="top" class="name"><g:message code="listing.id.label" default="Id" /></th>
                                <th valign="top" class="name"><g:message code="listing.listName.label" default="List Name" /></th>
                                <th valign="top" class="name"><g:message code="listing.creationDate.label" default="Creation Date" /></th>
                                <g:if test="${listingInstance.description != null && !listingInstance.description.allWhitespace}">
                                    <th valign="top" class="name"><g:message code="listing.description.label" default="Description" /></th>
                                </g:if>
                                <th valign="top" class="name"><g:message code="listing.startBidPrice.label" default="Starting Bid Price" /></th>
                                <th valign="top" class="name"><g:message code="listing.seller.emailAddress.label" default="Seller" /></th>
                                <th valign="top" class="name"><g:message code="listing.endDateTime.label" default="End Date Time" /></th>
                            </tr>
                            <tr>
                                <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "id")}</td>
                                <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "listName")}</td>
                                <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "creationDate")}</td>
                                <g:if test="${listingInstance.description != null && !listingInstance.description.allWhitespace}">
                                    <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "description")}</td>
                                </g:if>
                                <td valign="top" class="value"><g:formatNumber number="${listingInstance.startBidPrice}" type="currency" currencyCode="USD" /></td>
                                <td><g:link controller="customer" action="show" id="${listingInstance.seller.id}">${listingInstance.seller.getLoginName()}</g:link></td>
                                <td valign="top" class="value">${fieldValue(bean: listingInstance, field: "endDateTime")}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <%-- Only allow the sellers to update/delete their listing --%>
                <g:if test="${session?.customer?.getId() == listingInstance?.seller?.getId()}">
                    <div class="buttons">
                        <g:form>
                            <g:hiddenField name="id" value="${listingInstance?.id}" />
                            <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
                            <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
                        </g:form>
                    </div>
                </g:if>

                <script type="text/javascript">
                    function getValues() {
                        <g:remoteFunction controller="listing"  action="showRecentBids" update="bidList" onFailure="bidListFailure" params='[listName:listingInstance.listName]'></g:remoteFunction>
                        <g:remoteFunction controller="listing"  action="showWinningBidInfo" update="winningBidInfo" onFailure="bidListFailure" params='[listName:listingInstance.listName]'></g:remoteFunction>
                    }
                    new PeriodicalExecuter(getValues,1);
                </script>
                <div id="updateMe">
                    <g:render template="/listing/showWinningBid" model="['Listing':listingInstance]" >Place Bid</g:render>
                </div>
                <g:if test="${listingInstance?.endDateTime > new Date()}">
                    <g:render template="/listing/placeBid" model="[listingInstance:listingInstance]">Place Bid</g:render>
                </g:if>
                <g:render template="/listing/recentBidList" >Show Recent Bids</g:render>
            </g:unless>
        </div>
    </body>
</html>